package com.example.mybatisplus.web.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.mybatisplus.common.utls.SessionUtils;
import com.example.mybatisplus.model.dto.PageDTO;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.stereotype.Controller;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.example.mybatisplus.common.JsonResponse;
import com.example.mybatisplus.service.UserService;
import com.example.mybatisplus.model.domain.User;

@RestController
@RequestMapping("/api/user")
public class UserController {

    @Autowired
    private UserService userService;

    @PostMapping("login")
    @ResponseBody
    public JsonResponse login(@RequestBody User user){
        User login = userService.login(user);
        return JsonResponse.success(login);
    }

    @GetMapping("pageList")
    public JsonResponse pageList(User user, PageDTO dto){
        Page<User> page = userService.pageList(user,dto);
        return JsonResponse.success(page);
    }

    @PostMapping("edit")
    public JsonResponse edit(@RequestBody User user){
        boolean b = userService.updateById(user);
        return JsonResponse.success(b);
    }
}

